package com.jzhao.jpre.service.backend.impl;

import com.jzhao.jpre.base.Assembler;
import com.jzhao.jpre.base.DataCommIOException;
import com.jzhao.jpre.base.DataCommRecvErrorException;

public class TestTcpSyncShortComm {
	class TestThread implements Runnable {
		Thread t = null;

		TestThread() {
			t = new Thread(this);
			t.start();
		}

		public void run() {
			TcpSyncShortComm tcpSyncShortComm = (TcpSyncShortComm) Assembler
					.getInstance("WaterComm");
			try {
				tcpSyncShortComm.connect();
			} catch (DataCommIOException ioe) {
				System.out.println(ioe.getMessage());
				return;
			}

			byte[] sendArray = "AA  5601021000112345CDSZLS                         98016".getBytes();
			try {
				tcpSyncShortComm.send(sendArray);
			} catch (DataCommIOException ioe) {
				System.out.println(ioe.getMessage());
				return;
			}

			byte[] recvArray = null;
			try {
				recvArray = (byte[]) tcpSyncShortComm.recv();
				System.out.println(new String(recvArray));
			} catch (DataCommRecvErrorException ioe) {
				System.out.println(ioe.getMessage());
				return;
			}

			tcpSyncShortComm.release();
		}
	}

	public static void main(String[] args) {
		TestTcpSyncShortComm test = new TestTcpSyncShortComm();
		Assembler.start();
		for(int concurrent = 0; concurrent < 1; concurrent++) {
			test.new TestThread();
		}
	}
}
